var maxProfit = function(prices) {
    let ret=0;
    let maxP=new Array(prices.length).fill(0);
    function traverse(index,profit){
        //console.log(index,profit);
        if(index>=prices.length-1){
            ret=Math.max(ret,profit);
            return ;
        }
        if(profit>=maxP[index]){
            maxP[index]=profit;
            for(let i=index+1;i<prices.length;i++){
                if(prices[i]>prices[index]){
                    for(let k=i+2;k<prices.length+2;k++){
                        traverse(k,profit+prices[i]-prices[index]);
                    }
                }
            }
            // if(prices[prices.length-1]>prices[index]){
            //     profit+=prices[prices.length-1]-prices[index];
            // }
            //ret=Math.max(ret,profit);
        }
    }
    for(let j=0;j<prices.length-1;j++){
        traverse(j,0);
    }
    return ret;
};

//超时